ErrorHandler.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 3 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 3
b 3
f 0
1
/*eslint no-console: 0 */
2
3
class ErrorHandler{
4
	constructor(api){
5
		this.api = api;
6
	}
7
8
	handleCatch(e){
9
		// If babel supported extending of Error in a correct way instanceof would be used here
10
		if(e.name === "InvalidInputException"){
11
			if(this.api._options.valid !== this.api._defaults.valid){
12
				this.api._options.valid(false);
13
			}
14
			else{
15
				throw e.message;
16
			}
17
		}
18
		else{
19
			throw e;
20
		}
21
22
		this.api.render = function(){};
23
	}
24
25
	wrapBarcodeCall(func){
26
		try{
27
			var result = func(...arguments);
28
			this.api._options.valid(true);
29
			return result;
30
		}
31
		catch(e){
32
			this.handleCatch(e);
33
34
			return this.api;
35
		}
36
	}
37
}
38
39
export default ErrorHandler;
40